#include <dht11.h>                                               //引用dht11库文件，使得下面可以调用相关参数
#include"hz.c"
#define DHT11PIN 8                                             //定义温湿度针脚号为2号引脚
dht11 DHT11;                                                       //实例化一个对象
int pinBuzzer = 5; //管脚D3连接到蜂鸣器元件的基极

void setup() {                                                       //设置

Serial.begin(9600);                                            //设置波特率参数
Serial2.begin(9600);
Serial3.begin(115200);
while (!Serial) {
     // wait for serial line to be ready
  }
Serial3.print("CLS(0);");
Serial3.print("DS16(20,2,'");Serial3.print(hz[1]);Serial3.print("',4);");
Serial3.print("DS16(20,22,'");Serial3.print(hz[2]);Serial3.print("',15);");
Serial3.println("PL(0,40,399,40,1);");Serial3.flush();delay(200);

  
pinMode(DHT11PIN,OUTPUT);                       //定义输出口
}

void loop() {                                                    //循环
int chk = DHT11.read(DHT11PIN);                 //将读取到的值赋给chk

float ftem=(float)DHT11.temperature;
float fhum=(float)DHT11.humidity;

int tem=(float)DHT11.temperature;               //将温度值赋值给tem
int hum=(float)DHT11.humidity;                   //将湿度值赋给hum
Serial.print("Tempeature:");                        //打印出Tempeature:
Serial.println(tem);                                     //打印温度结果


//Serial2.print("Tempeature:");                        //打印出Tempeature:
//Serial2.println(tem);

Serial.print("Humidity:");                            //打印出Humidity:
Serial.print(hum);                                     //打印出湿度结果
Serial.println("%");                                  //打印出%

//Serial2.print("Humidity:");                            //打印出Humidity:
//Serial2.print(hum);                                     //打印出湿度结果
//Serial2.println("%"); 


//Serial2.write(lowByte(hum)); //send the low byte
Serial2.write(lowByte(hum)); //send the low byte
Serial2.write(highByte(hum)); //send the high byte

  
//打印出%
Serial2.write(lowByte(tem)); //send the low byte
Serial2.write(highByte(tem)); //send the high byte
//Serial2.write(lowByte(tem)); //send the low byte

if(tem>30&&hum<30){
  digitalWrite(pinBuzzer, HIGH);//输出HIGH电平,停止发声
   delay(3000); //等待3000毫秒w
 
   digitalWrite(pinBuzzer, LOW);//输出LOW电平,发声
   delay(1000); //等待1000毫秒
}else if(tem<10&&hum>80){
  digitalWrite(pinBuzzer, HIGH);//输出HIGH电平,停止发声
   delay(3000); //等待3000毫秒w
 
   digitalWrite(pinBuzzer, LOW);//输出LOW电平,发声
   delay(1000); //等待1000毫秒
}


  Serial3.print("DS24(30,100,'");
  Serial3.print(hz[0]);
  Serial3.print(ftem,2);
  Serial3.println("C',1);");
  delay(150);        // delay in between reads for stability

   Serial3.print("DS24(30,150,'");
  Serial3.print(hz[3]);
  Serial3.print(fhum,2);
  Serial3.println("C',1);");
  delay(150);        // delay in between reads for stability



delay(1000);                                          //延时一段时间

}
